package com.fjrcloud.controller;

import com.fjrcloud.entity.Basement;
import com.fjrcloud.entity.HousingNature;
import com.fjrcloud.entity.ResponseBean;
import com.fjrcloud.entity.ResponseFactory;
import com.fjrcloud.exception.BusinessException;
import com.fjrcloud.service.IdentifiedHomesteadService;
import com.fjrcloud.service.IdentifiedHousingService;
import com.fjrcloud.service.IdentifiedLandService;
import com.fjrcloud.service.IdentifiedStorefrontService;
import com.fjrcloud.utils.StatusUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by shengjian.lin on 2017/1/21.
 */
@Controller
@RequestMapping("api/identified")
public class IdentifiedController {

    @Autowired
    private IdentifiedLandService identifiedLandService;
    @Autowired
    private IdentifiedHousingService identifiedHousingService;
    @Autowired
    private IdentifiedStorefrontService identifiedStorefrontService;
    @Autowired
    private IdentifiedHomesteadService identifiedHomesteadService;

    @RequestMapping("land/save")
    @ResponseBody
    public ResponseBean landSave(Integer id,Integer masterId,Integer standardId,Double area,String description) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success, identifiedLandService.save(id,masterId,standardId,area,description));
    }

    @RequestMapping("land/find")
    @ResponseBody
    public ResponseBean landFind(Integer masterId,Integer pageNum, Integer pageSize) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success, identifiedLandService.find(masterId,pageNum,pageSize));
    }

    @RequestMapping("land/get")
    @ResponseBody
    public ResponseBean landGet(Integer id) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success, identifiedLandService.get(id));
    }

    @RequestMapping("land/del")
    @ResponseBody
    public ResponseBean landDel(Integer id) throws BusinessException {
        identifiedLandService.del(id);
        return ResponseFactory.getResponseBean(StatusUtils.Success);
    }

    @RequestMapping("housing/save")
    @ResponseBody
    public ResponseBean housingSave(
            Integer id,
            Integer masterId,
            Integer landStandardId,
            Integer structureLevelId,
            Integer structureIntoNewId,
            Integer decorateLevelId,
            Integer decorateIntoNewId,
            Integer layer,
            HousingNature nature,
            Basement basement,
            Boolean attic,
            Boolean atticHighly,
            Double area,
            String description) throws BusinessException {
        return ResponseFactory.getResponseBean(
                StatusUtils.Success,
                identifiedHousingService.save(
                        id,
                        masterId,
                        landStandardId,
                        structureLevelId,
                        structureIntoNewId,
                        decorateLevelId,
                        decorateIntoNewId,
                        layer,
                        nature,
                        basement,
                        attic,
                        atticHighly,
                        area,
                        description
                )
        );
    }
    @RequestMapping("housing/find")
    @ResponseBody
    public ResponseBean housingFind(Integer masterId,Integer pageNum, Integer pageSize) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success, identifiedHousingService.find(masterId,pageNum,pageSize));
    }

    @RequestMapping("housing/get")
    @ResponseBody
    public ResponseBean housingGet(Integer id) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success, identifiedHousingService.get(id));
    }
    @RequestMapping("housing/del")
    @ResponseBody
    public ResponseBean housingDel(Integer id) throws BusinessException {
        identifiedHousingService.del(id);
        return ResponseFactory.getResponseBean(StatusUtils.Success);
    }

    @RequestMapping("storefront/save")
    @ResponseBody
    public ResponseBean storefrontSave(Integer id,Integer masterId,Integer standardId,Double area,String description) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success, identifiedStorefrontService.save(id,masterId,standardId,area,description));
    }

    @RequestMapping("storefront/find")
    @ResponseBody
    public ResponseBean storefrontFind(Integer masterId,Integer pageNum, Integer pageSize) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success, identifiedStorefrontService.find(masterId,pageNum,pageSize));
    }

    @RequestMapping("storefront/get")
    @ResponseBody
    public ResponseBean storefrontGet(Integer id) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success, identifiedStorefrontService.get(id));
    }

    @RequestMapping("storefront/del")
    @ResponseBody
    public ResponseBean storefrontDel(Integer id) throws BusinessException {
        identifiedStorefrontService.del(id);
        return ResponseFactory.getResponseBean(StatusUtils.Success);
    }

    @RequestMapping("homestead/save")
    @ResponseBody
    public ResponseBean homesteadSave(Integer id,Integer masterId,Double area,String description) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success, identifiedHomesteadService.save(id,masterId,area,description));
    }

    @RequestMapping("homestead/find")
    @ResponseBody
    public ResponseBean homesteadFind(Integer masterId,Integer pageNum, Integer pageSize) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success, identifiedHomesteadService.find(masterId,pageNum,pageSize));
    }

    @RequestMapping("homestead/get")
    @ResponseBody
    public ResponseBean homesteadGet(Integer id) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success, identifiedHomesteadService.get(id));
    }

    @RequestMapping("homestead/del")
    @ResponseBody
    public ResponseBean homesteadDel(Integer id) throws BusinessException {
        identifiedHomesteadService.del(id);
        return ResponseFactory.getResponseBean(StatusUtils.Success);
    }
}
